<template>
	<el-dialog :title=title :visible.sync="dialogVisible" width="800" @close="handleClose"
		:close-on-click-modal="false">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>{{title}}</span>
		</div>

		<div class="smp-search" v-if="dialogVisible">
			<el-form :inline="false" label-width="150px" size="mini" ref="form" :model="form" :rules="rules">

				<el-row>
					<el-col :span="24">
						<el-form-item label="需求编号:" prop="qmsNo">
							<el-input v-model="form.qmsNo" placeholder="需求编号" disabled></el-input>
						</el-form-item>
					</el-col>
				
					<el-col :span="24">
						<el-form-item label="批次号:" prop="batchNum">
							<el-input v-model="form.batchNum" placeholder="批次号" disabled></el-input>
						</el-form-item>
					</el-col>
					
					<el-col :span="24">
						<el-form-item label="版本类型:" :label-col="{ span: 5 }" :wrapper-col="{ span: 16  }" prop="relaseType">
							<el-select v-model="form.relaseType" style="width: 100%" placeholder="版本类型" disabled>
								<el-option v-for="item in dict('SMP0024')" :key="item.itemCode"
									:label="item.itemName" :value="item.itemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
						
					<el-col :span="24">
						<el-form-item :label="'内联'+title+':'" prop="esbRelase">
							<el-input v-model="form.esbRelase" placeholder="内联版本基线号"></el-input>
						</el-form-item>
					</el-col>
					
					<el-col :span="24">
						<el-form-item :label="'外联'+title+':'">
							<el-input v-model="form.oesbRelase" placeholder="外联版本基线号"></el-input>
						</el-form-item>
					</el-col>
					
					<el-col :span="24">
						<el-form-item label="提交版本时间">
							<el-date-picker value-format="yyyy-MM-dd hh:mm:ss" style="width: 100%" v-model="form.updateTime" type="datetime"  placeholder="选择日期">
							</el-date-picker>
							<!-- <el-input v-model="form.oesbRelase" placeholder="外联版本基线号"></el-input> -->
						</el-form-item>
					</el-col>
					
				</el-row>
			</el-form>
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button size="mini" type="primary" @click="onSubmit">确定</el-button>
			<el-button size="mini" @click="closeDialog">取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import { updateRelaseInfo } from '@/api/requirementBatch.js';

	export default {

		data() {
			return {
				dialogVisible: false,
				title:'',
				
				rules: {
				/* 	esbRelase: [{
						required: true,
						message: "版本基线号不能为空",
						trigger: ['blur', 'change']
					}] */
				},
				
				form: {
					qmsNo: '',
					batchNum: '',
					relaseType:'',
					esbRelase: '',
					oesbRelase: '',
					updateTime:''
				},

			};
		},

		

		methods: {

			onSubmit() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						updateRelaseInfo(this.form).then(response => {
							/* if(response.data.code == '0000'){
								this.$message({
						duration:5000,
									type: 'success',
									message: response.data.message
								});
							}else{
								this.$message({
						duration:5000,									type: 'error',
									message: response.data.message
								});
							} */
							this.form.esbRelase = '';
							this.form.oesbRelase = '';
							this.dialogVisible = false;
							this.$emit("getInit");
				
						}).catch(error => {
							this.$message({
						duration:5000,							type: 'error',
								message: '版本基线号更新失败！'
							});
							this.form.esbRelase = '';
							this.form.oesbRelase = '';
							this.dialogVisible = false;
							this.$emit("getInit");
						});
					}
				})
			},

			showDialog(row,val) {
				this.title = val;
				this.form.qmsNo = row.qmsNo;
				this.form.batchNum = row.batchNum;
				
				
				if("测试基线号" == val){
					this.form.relaseType = '01';
					if(row.esbSitRelase != undefined){
						this.form.esbRelase = row.esbSitRelase;
					}
					if(row.oesbSitRelase != undefined){
						this.form.oesbRelase = row.oesbSitRelase;
					}
					
				}else if("生产基线号" == val){
					this.form.relaseType = '02';
					if(row.esbOprdRelase != undefined){
						this.form.esbRelase = row.esbOprdRelase;
					}
					if(row.oesbOprdRelase != undefined){
						this.form.oesbRelase = row.oesbOprdRelase;
					}
					
				}
				this.dialogVisible = true;
			},

			closeDialog() {
				this.form.esbRelase = '';
				this.form.oesbRelase = '';
				this.dialogVisible = false;
			},

			handleClose() {
				this.form.esbRelase = '';
				this.form.oesbRelase = '';
				this.dialogVisible = false;
			}

		},

	}
</script>

<style>
</style>
